#include "progress_bar.h"
#include "sprite.h"
#include "game_engine.h"
#include "utility.h"

ProgressBar::ProgressBar(std::string emptyResourceName, std::string fullResourceName)
	: Sprite(emptyResourceName, true) //RenderTarget("progress_bar")
{
	fullResource = fullResourceName;
	percentProgress = 0.0;
}

void ProgressBar::Render(SDL_Surface *screen)
{
	Sint16 dx, dy;

	SDL_Surface* img = NULL;
	//Get image to render
	img = getRenderImage();
	if (img != NULL)
	{
		getScreenCoords(dx, dy);

		apply_surface(dx, dy, img, screen);

		if (percentProgress > 0)
		{
			SDL_Surface* overlay = GameEngine::getResources()->GetImage(fullResource, true);
			apply_partial_surface(0, 0, (Uint16)(overlay->w * percentProgress / 100.0), overlay->h, dx, dy, overlay, screen);
		}
	}
	//Render children
    RenderTarget::Render(screen);
}

